﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MediaClient.Common;
using System.IO;
using System.Threading;

namespace MediaClient.Publish
{
    public partial class CheckWaterMarkerForm : BaseSmallForm
    {
        DetectionWaterMarkHelper dApp = new DetectionWaterMarkHelper();

        public static string sourceFile = "";

        public static string targetFile = "F:\\DLL\\temp.mpg";

        public CheckWaterMarkerForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (dApp != null)
            {
                if (File.Exists(targetFile) == true)
                {
                    try
                    {
                        File.Delete(targetFile);
                    }
                    catch { }
                }
                if (string.IsNullOrEmpty(sourceFile) == true)
                {
                    MessageBox.Show("请选择需要检测水印的源文件！");
                }
                else
                {
                    dApp.InitialFlexDetectionWaterMark(sourceFile, targetFile);
                    Thread.Sleep(500);
                    int num = 0;
                    try 
                    {
                        num = Convert.ToInt32(textBox1.Text);
                    }
                    catch
                    {
                        num = 0;
                    }
                    if (num == 0)
                    {
                        MessageBox.Show("输入的检测间隔值无效！","友情提示");
                    }
                    dApp.SetDetectionWaterMarkParam(num,7);
                    Thread.Sleep(200);
                    dApp.StartFlexDetectionWaterMark();
                    timer1.Start();
                }

            }
        }

        private void GetWaterMarkPic()
        { 
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSoufceFileBrower_Click(object sender, EventArgs e)
        {
            OpenFileDialog file = new OpenFileDialog();
            file.RestoreDirectory = true;
            file.Filter = "MPEG FILL(*.mpg)|*.mpg";
            if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                sourceFile = file.FileName;
                tbxSourceFilePath.Text = sourceFile;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            if (dApp.GetProcess() >= 1)
            {
                timer1.Stop();
                MessageBox.Show("检测结束!", "友情提示");
            }
            try
            {
                Image img = Image.FromFile(@"d:\3333333.bmp");
                pictureBox1.Image = img;
            }
            catch(Exception myex)
            {
                //throw myex;
            }
        }

        private void btnControl_MouseLeave(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            if (btn != null)
            {
                switch (btn.Name)
                {
                    case "btnSoufceFileBrower":
                        btnSoufceFileBrower.Image = global::MediaClient.Properties.Resources.浏览;
                        break;
                    case "btnCheck":
                        btnCheck.Image = global::MediaClient.Properties.Resources.开始检测;
                        break;
                    case "btnQuit":
                        btnQuit.Image = global::MediaClient.Properties.Resources.退出;
                        break;
                }
            }
        }

        private void btnControl_MouseMove(object sender, MouseEventArgs e)
        {
            Button btn = sender as Button;
            if (btn != null)
            {
                switch (btn.Name)
                {
                    case "btnSoufceFileBrower":
                        btnSoufceFileBrower.Image = global::MediaClient.Properties.Resources.浏览_1;
                        break;
                    case "btnCheck":
                        btnCheck.Image = global::MediaClient.Properties.Resources.开始检测_1;
                        break;
                    case "btnQuit":
                        btnQuit.Image = global::MediaClient.Properties.Resources.退出_1;
                        break;
                }
            }
        }
    }
}
